<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<u--form>
				<u-form-item label="用户名" label-width="100rpx">
					<u--input v-model="userForm.username"></u--input>
				</u-form-item>
				<u-form-item label="密码" label-width="100rpx">
					<u--input v-model="userForm.password"></u--input>
				</u-form-item>
				<u-form-item>
					<u-button type="primary" @click="onLogin">登录</u-button>
				</u-form-item>
				<u-form-item>
					<u-button type="primary" @click="testLogin">测试登录</u-button>
				</u-form-item>
			</u--form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userForm: {
					username: '',
					password:''
				}
			}
		},
		onLoad() {
			
			

		},
		methods: {
			
			onLogin() {
				uni.$u.http.get('/users/login', this.userForm).then((res) => {
					const token = res.data.token
					uni.setStorageSync('token', token)
				}).catch((err) => {
					console.log(err)
				})
			},
			
			testLogin() {
				uni.$u.http.get('/users').then((res) => {
					console.log(res);
				}).catch((err) => {
					console.log(err)
				})
			}

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
